/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.j2eem.Mapper.wcymapper;

import com.mycompany.j2eem.Entity.FavoriteId;
import com.mycompany.j2eem.Entity.InsertName;
import com.mycompany.j2eem.Entity.Movement;
import com.mycompany.j2eem.Entity.NewMovement;
import com.mycompany.j2eem.Entity.PersonalHubId;
import com.mycompany.j2eem.Entity.PersonalInformation;
import com.mycompany.j2eem.Entity.PictureId;
import com.mycompany.j2eem.Entity.PictureInfor;
import com.mycompany.j2eem.Entity.PictureInformation;
import com.mycompany.j2eem.Entity.Test;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 *
 * @author asus
 */
public interface PersonalHubMapper {

    //获取Account_id
    @Select("SELECT id from Account where username =#{username}")
    String getAccountId(@Param("username") String username);

    //获取图片现在的情况
    @Select("Select private from Picture where id = #{id}")
    String getPrivate(@Param("id") String id);

    //修改图片情况
    @Update("Update Picture set private = #{situation} where id = #{id}")
    int change(@Param("id") String id, @Param("situation") String situation);

    //获取收藏夹名字
    @Select("Select favoritename,id from getFavorite where Account_id =#{Account_id}")
    List<FavoriteId> getFavoriteName(@Param("Account_id") String Account_id);

    //获取个人仓库名字
    @Select("Select PersonalHubname,id from getPersonalHub where Account_id =#{Account_id}")
    List<PersonalHubId> getPersonalHubName(@Param("Account_id") String Account_id);

    //创建收藏夹
    @Insert("Insert into Favorite_name(favoritename) value(#{name});")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int createFavorite(InsertName insertName);

    @Insert("Insert into Favorite(Account_id,Favorite_name_id,private) value(#{Account_id},#{id},'public')")
    int create_favorite_two(@Param("Account_id") String Account_id, @Param("id") String id);

    /**
     * 创建个人仓库
     */
    @Insert("Insert into PersonalHub_name(PersonalHubname) value(#{name})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int createPersonalHub(InsertName insertName);

    @Insert("Insert into PersonalHub(Account_id,PersonalHub_name_id) value(#{Account_id},#{id})")
    int createPersonalHubtwo(@Param("Account_id") String Account_id, @Param("id") String id);

    //收藏到收藏夹
    @Insert("Insert into Favorite_picture(Favorite_id,Picture_id) value(#{favorite_id},#{picture_id})")
    int favoritePicture(@Param("favorite_id") String favorite_id, @Param("picture_id") String picture_id);

    //图片
    @Insert("Insert into Picture(picturepath,private) value(#{name},'private')")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int upLoadPicture(InsertName insertName);

    //上传个人仓库
    @Insert("Insert into PersonalHub_picture(PersonalHub_id,Picture_id) value(#{personalHub_id},#{picture_id})")
    int upLoad(@Param("personalHub_id") String personalHub_id, @Param("picture_id") String picture_id);

    @Insert("Insert into PersonalHub_picture(PersonalHub_id,Picture_id) value(#{personalHub_id},#{picture_id})")
    int personalHubPicture(@Param("personalHub_id") String personalHub_id, @Param("picture_id") String picture_id);

    //移动收藏夹
    @Update("Update Favorite_picture set Favorite_id = #{new_id} where Picture_id = #{old_id} AND Favorite_id IN(SELECT id FROM Favorite WHERE Account_id = #{Account_id})")
    int changeFavorite(@Param("new_id") String id, @Param("old_id") String old_id, @Param("Account_id") String Account_id);

    //移动个人仓库
    @Update("Update PersonalHub_picture set PersonalHub_id = #{new_id} where Picture_id = #{old_id} AND PersonalHub_id IN(SELECT id FROM PersonalHub WHERE Account_id = #{Account_id})")
    int changePersonalHub(@Param("new_id") String id, @Param("old_id") String old_id, @Param("Account_id") String Account_id);

    //取消收藏
    @Delete("Delete from Favorite_picture where Picture_id = #{picture_id} and Favorite_id=#{favorite_id}")
    int cancelFavorite(@Param("picture_id") String picture_id, @Param("favorite_id") String favorite_id);

    //删除个人仓库的图片
    @Delete("Delete from PersonalHub_picture where Picture_id = #{picture_id} and PersonalHub_id=#{favorite_id}")
    int cancelPersonalHub(@Param("picture_id") String picture_id, @Param("favorite_id") String favorite_id);

    //删除收藏夹分类
    @Delete("Delete from Favorite_picture where Favorite_id = #{favorite_id}")
    int delteFavorite(@Param("favorite_id") String favorite_id);

    @Delete("DELETE FROM Favorite WHERE id = #{id}")
    int deleteMyfav(@Param("id") String id);

    //删除个人仓库
    @Delete("Delete from PersonalHub_picture where PersonalHub_id = #{favorite_id}")
    int deletePersonalHub(@Param("favorite_id") String favorite_id);

    @Delete("DELETE FROM PersonalHub WHERE id = #{id}")
    int deleteMyPersonalHub(@Param("id") String id);

    //加入标签名字
    @Insert("Insert into TagName(tagname,count) value(#{name},#{count})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addTagName(InsertName insertName);

    //加入标签
//    @Insert("Insert into Tag(TagName_id) value(#{id})")
//    String addTag(@Param("id") String id);
    //加入节点之间子关系
    @Insert("Insert into TagChildRelationship(TagName_id,TagName_Childt_id,num) value(#{TagName_id},#{TagName},#{num})")
    int addTagChildrenReationship(@Param("TagName_id") String TagName_id, @Param("TagName") String tagChildId, @Param("num") String num);

    //加入节点之间母关系
    @Insert("Insert into TagParentRelationship(TagName_id,TagName_parent_id,num) value(#{TagName_id},#{TagName_parent_id},#{num})")
    int addTagParentReationship(@Param("TagName_id") String TagName_id, @Param("TagName_parent_id") String tagChildId, @Param("num") String num);

    //发布
    @Insert("Insert into Movement(time,Account_id,title,available) value (now(),#{accountId},#{title},#{available})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int createMovement(Movement movement);

    @Insert("Insert into Tag_Movement(Movement_id,TagName_id) value (#{Movement_id},#{TagName_id})")
    int moveTag(@Param("Movement_id") String Movement, @Param("TagName_id") String TagName_id);

    @Insert("Insert Into Movement_Picture (Movement_id,Picture_id) value(#{Movement_id},#{Picture_id})")
    int pictureMovement(@Param("Movement_id") String movementId, @Param("Picture_id") String tagNameId);

    @Update("Update Picture set private = 'public' where id = #{id}")
    int updateState(@Param("id") String id);

    //获取标签ID
    @Select("Select TagName.id from TagName where TagName=#{name}")
    String getTagId(@Param("name") String name);

    //获取仓库图片
    @Select("Select picturepath,Picture.id,private state from Picture,PersonalHub_picture WHERE PersonalHub_id = #{id}  AND Picture_id = Picture.id")
    List<PictureInformation> getHubPath(@Param("id") String id);

    //获取仓库图片
    @Select("Select picturepath,Picture.id,private state from Picture,Favorite_picture WHERE Favorite_id = #{id}  AND Picture_id = Picture.id")
    List<PictureInformation> getFavoritePath(@Param("id") String id);

    @Select("Select id from PersonalHub where Account_id = #{id}")
    List<String> getMyHubId(@Param("id") String id);

    //喜欢
    @Insert("Insert into Like_picture(Account_id,Picture_id) value(#{accountId},#{pictureId})")
    int likePicture(@Param("accountId") String accountId, @Param("pictureId") String pictureId);
    
    @Delete("DELETE FROM Like_picture WHERE Account_id = #{accountId} AND Picture_id = #{pictureId}")
    int deletePicture(@Param("accountId") String accountId, @Param("pictureId") String pictureId);
    
    
    @Select("Select id from  Like_picture where Account_id = #{accountId} and Picture_id = #{pictureId}")
    String getIsLike(@Param("accountId") String accountId,@Param("pictureId") String pictureId); 

    //获取喜欢的列表
    @Select("Select Picture_id from Like_picture where Account_id=#{accountId}")
    List<String> getLikePicture(@Param("accountId") String accountId);
    
    //添加图片属性
    @Insert("Insert into Picture_Attritube(Picture_id,TagName_id) value(#{pictureId},#{TagName_id})")
    int addAttritube(@Param("pictureId") String pictureId, @Param("TagName_id") String TagName_id);

    //获取标签名
    @Select("Select id from TagName where tagname=#{tagname}")
    String ifTagExist(@Param("tagname") String tagname);

    //获取动态的时间，titl,用户
    @Select("Select id,time,title,available,id from Movement where Account_id = #{id} ORDER BY time DESC;")
    List<NewMovement> getMovement(@Param("id") String id);

    //获取当前动态下的图片
    @Select("Select Picture_id,picturepath from Movement_Picture,Picture where Movement_id = #{id} and Picture_id = Picture.id")
    List<PictureId> getMovementPicture(@Param("id") String id);

    //获取关注列表
    @Select("Select Account_id_b from follow where Account_id_a = #{id}")
    List<String> getFollowList(@Param("id") String id);

    //获取动态ID
    @Select("Select id from Movement where Account_id = #{id}")
    List<String> getMovementId(@Param("id") String id);

    //获取收藏夹图片
    @Select("SELECT Picture_id from  Favorite,Favorite_picture where Favorite_id = Favorite.id and Account_id = #{id}")
    List<String> getFavoritePicture(@Param("id") String id);

    //返回图片信息
    @Select("SELECT picturepath,TagName FROM Picture,TagName,Picture_Attritube WHERE Picture_id = Picture.id and TagName_id = TagName.id and Picture.id =#{id}")
    List<PictureInfor> getPictureInfor(@Param("id") String id);
    
   //返回图片路径
    @Select("SELECT picturepath FROM Picture WHERE Picture.id = #{id}")
    String getPicturepath(@Param("id") String id);

    //图片用户喜欢数
    @Select("Select count(*) from Like_picture where Picture_id = #{Picture_id}")
    String userLikeNum(@Param("Picture_id") String id);

    //图片用户收藏数
    @Select("Select count(*) from Favorite_picture where Picture_id = #{Picture_id}")
    String userFavoriteNum(@Param("Picture_id") String id);

    //图片是否喜欢过
    @Select("Select id from Like_picture where Account_id = #{accountId} and Picture_id=#{pictureId}")
    String isLike(@Param("accountId") String accountId, @Param("pictureId") String pictureId);

    //获取图片发布者信息
    @Select("SELECT picture,nickname,Account_id FROM `User` WHERE Account_id IN (SELECT Account_id FROM Movement,Movement_Picture WHERE Movement_id = Movement.id AND Picture_id = #{id})")
    PersonalInformation getFaBuInfor(@Param("id") String id);
    
    
    
    //获取发布个数
    @Select("SELECT count(*) from Movement_Picture,Movement   WHERE Movement_id = Movement.id AND Account_id = #{id} GROUP BY Account_id;")
    String getFaBunum(@Param("id") String id);
}
